<?php
/**
 * Created by PhpStorm.
 * User: v_shiyanjun
 * Date: 2018/12/28
 * Time: 下午6:07
 */

//数据库配置
$db = array(
    'host' => 'localhost',
    'port' => '3306',
    'dbname' => 'yafblog',
    'username' => 'root',
    'password' => '123456',
    'dsn' => 'mysql:host=127.0.0.1;dbname=yafblog;port=3306;charset=utf8',
);
try {
    $pdo = new PDO($db['dsn'], $db['username'], $db['password'], array());
    $res = $pdo->query('select * from  cat');
    $data = $res->fetchAll();
    if ($data) {
        foreach ($data as $d) {
            echo $d['comment'] . "<br>";
        }
    }
} catch (PDOException $e) {
    die($e->getMessage());
}